<?php
declare (strict_types = 1);

namespace app\middleware;

use MoCommon\Support\Codes;

class ApiLoginCheck
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        //也可以放在路由里面加中间件限制；这里放在配置文件middleware.php里面配置了
        $exceptUrl=["/api/account/login","/api/article/list","/api/article/detail"];
        $url=$request->url();
        if(!in_array($url,$exceptUrl)&&!strstr($url,"/api/wechat/")){
            $token=input("token");
            if(empty($token)||$token=="undefined"){
                //没登录；
                return json(["status" => Codes::NO_SIGNIN, "msg" => Codes::get(Codes::NO_SIGNIN), "data" => []]);
            }
        }
        return $next($request);
    }
}
